package cn.bonoon.kernel.support;

public final class CipherGenerator {
	private final long seed;
	public static boolean support(Class<?> type){
		return String.class.equals(type)
				|| int.class.equals(type)
				|| long.class.equals(type)
				|| Integer.class.equals(type)
				|| Long.class.equals(type);
	}
	public CipherGenerator(long seed){
		this.seed = seed;
	}
	public int decrypt(int target){
		return (int) (target ^ seed);
	}
	public int encrypt(int target){
		return (int) (target ^ seed);
	}
	public Integer decrypt(Integer target){
		if(null != target){
			return (int) (target ^ seed);
		}
		return null;
	}
	public Integer encrypt(Integer target){
		if(null != target){
			return (int) (target ^ seed);
		}
		return null;
	}
	public long decrypt(long target){
		return target ^ seed;
	}
	public long encrypt(long target){
		return target ^ seed;
	}
	public Long decrypt(Long target){
		if(null != target){
			return target ^ seed;
		}
		return null;
	}
	public Long encrypt(Long target){
		if(null != target){
			return target ^ seed;
		}
		return null;
	}
	public String decrypt(String target){
		if(null == target) return null;
		char[] cs = target.toCharArray();
		for(int i = 0; i < cs.length; i++){
			cs[i] = (char) (cs[i] ^ seed);
		}
		return new String(cs);
	}
	public String encrypt(String target){
		if(null == target) return null;
		char[] cs = target.toCharArray();
		for(int i = 0; i < cs.length; i++){
			cs[i] = (char) (cs[i] ^ seed);
		}
		return new String(cs);
	}
}
